home *** CD-ROM | disk | FTP | other *** search
/ Revista do CD-ROM 97 / CD-ROM 97 / CD-ROM 97.iso / internet / ghostzilla / ghsetup.exe / chrome / comm.jar / content / communicator / pref / pref-winhooks.js < prev    next >
Encoding:
Text File  |  2002-04-10  |  4.8 KB  |  144 lines

  1. /* -*- Mode: C++; tab-width: 4; c-basic-offset: 4; -*-
  2.  * 
  3.  * The contents of this file are subject to the Netscape Public License
  4.  * Version 1.0 (the "NPL"); you may not use this file except in
  5.  * compliance with the NPL.  You may obtain a copy of the NPL at
  6.  * http://www.mozilla.org/NPL/
  7.  *
  8.  * Software distributed under the NPL is distributed on an "AS IS" basis,
  9.  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
  10.  * for the specific language governing rights and limitations under the
  11.  * NPL.
  12.  *
  13.  * The Initial Developer of this code under the NPL is Netscape
  14.  * Communications Corporation.  Portions created by Netscape are
  15.  * Copyright (C) 1998 Netscape Communications Corporation.  All Rights
  16.  * Reserved.
  17.  *
  18.  * Contributor(s):
  19.  *  Bill Law    <law@netscape.com>
  20.  */
  21.  
  22. // Turn this on to get debug output.
  23. const debug = 1;
  24. function debugDump( text ) {
  25.     if ( debug ) {
  26.         dump( text + "\n" );
  27.     }
  28. }
  29. function dumpObject( obj, name ) {
  30.     for ( prop in obj ) {
  31.         debugDump( name + "." + prop + "=" + obj[prop] );
  32.     }
  33. }
  34.  
  35. // Top-level windows integration preferences.
  36. if ( !( "winHooks" in parent ) ) {
  37.     parent.winHooks = new Object;
  38.     parent.winHooks.settings = [ "isHandlingHTML",
  39.                                  "isHandlingJPEG",
  40.                                  "isHandlingGIF",
  41.                                  "isHandlingPNG",
  42.                                  "isHandlingMNG",
  43.                                  "isHandlingBMP",
  44.                                  "isHandlingICO",
  45.                                  "isHandlingXML",
  46.                                  "isHandlingXHTML",
  47.                                  "isHandlingXUL",
  48.                                  "isHandlingHTTP",
  49.                                  "isHandlingHTTPS",
  50.                                  "isHandlingFTP",
  51.                                  "isHandlingCHROME",
  52.                                  "isHandlingGOPHER",
  53.                                  "showDialog" ];
  54.     
  55.     parent.winHooks.winhooks = null;
  56.     parent.winHooks.prefs = null;
  57. }
  58.  
  59. // This function is called when the user presses Ok to close the prefs window.
  60. function onOK() {
  61.     try {
  62.         // Get updates from dialog if we're displayed.
  63.         if ( "GetFields" in window ) {
  64.             GetFields();
  65.         }
  66.         // Update prefs.
  67.         parent.winHooks.winhooks.settings = parent.winHooks.prefs;
  68.     }
  69.     catch(e) {
  70.         dump( e + "\n" );
  71.     }
  72. }
  73.  
  74. var gPrefService = null;
  75. var gPrefBranch = null;
  76.  
  77. // This function is called when our pref panel is loaded.
  78. function Startup() {
  79.  
  80.     const prefbase = "system.windows.lock_ui.";
  81.  
  82.     // initialise preference component.
  83.     // While the data is coming from the system registry, we use a set
  84.     // of parallel preferences to indicate if the ui should be locked.
  85.     if (!gPrefService) {
  86.         gPrefService = Components.classes["@mozilla.org/preferences-service;1"];
  87.         gPrefService = gPrefService.getService();
  88.         gPrefService = gPrefService.QueryInterface(Components.interfaces.nsIPrefService);
  89.         gPrefBranch = gPrefService.getBranch(prefbase);
  90.     }
  91.  
  92.  
  93.     // Get globals.
  94.     var settings = parent.winHooks.settings;
  95.     var winhooks = parent.winHooks.winhooks;
  96.     var prefs    = parent.winHooks.prefs;
  97.     if ( !winhooks ) {
  98.         // Get component service.
  99.         try {
  100.             winhooks = Components.classes[ "@mozilla.org/winhooks;1" ].getService( Components.interfaces.nsIWindowsHooks );
  101.             if ( winhooks ) {
  102.                 // Try to get preferences.
  103.                 prefs = winhooks.settings;
  104.                 // Set globals.
  105.                 parent.winHooks.winhooks = winhooks;
  106.                 parent.winHooks.prefs    = prefs;
  107.                 // Register so we get called when pref window Ok is pressed.
  108.                 parent.hPrefWindow.registerOKCallbackFunc( onOK );
  109.             }
  110.         }
  111.         catch(e) {
  112.             dump( e + "\n" );
  113.         }
  114.     }         
  115.     // Transfer object settings to the dialog checkboxes.
  116.     for( var index in settings  ) {
  117.         var setting = settings[ index ];
  118.         var checkbox = document.getElementById( setting );
  119.         if ( checkbox && prefs[ setting ] ) {
  120.             checkbox.setAttribute( "checked", "true" );
  121.         }
  122.  
  123.         // disable the xul element if the appropriate pref is locked.
  124.         if (gPrefBranch && gPrefBranch.prefIsLocked(setting)) {
  125.             checkbox.disabled = true;
  126.         }
  127.     }
  128. }
  129.  
  130. function GetFields() {
  131.     // Get globals.
  132.     var settings = parent.winHooks.settings;
  133.     var winhooks = parent.winHooks.winhooks;
  134.     var prefs    = parent.winHooks.prefs;
  135.     // Transfer data from dialog to prefs object.
  136.     for( var index in settings ) {
  137.         var setting = settings[ index ];
  138.         var checkbox = document.getElementById( setting );
  139.         if ( checkbox ) {
  140.             prefs[ setting ] = checkbox.checked;
  141.         }
  142.     }
  143. }
  144.